class Helper {
	constructor(arg) {
		
	}
	
	static formatRichText(html) {
		let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
			match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
			match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
			match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
			return match;
		});
		newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
			match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');
			return match;
		});
		newContent = newContent.replace(/<br[^>]*\/>/gi, '');
		newContent = newContent.replace(/\<img/gi,
			'<img style="max-width:100%;height:auto;display:inline-block;margin:10rpx auto;"');
		return newContent;
	}
	
	
	static formatTime(time) {
		var a = ["日", "一", "二", "三", "四", "五", "六"];  
		var week = new Date(time).getDay();  
		var str = "星期"+ a[week];
	}
	
	static getWeek(time) {
		var a = ["日", "一", "二", "三", "四", "五", "六"];
		var week = new Date(time*1000).getDay();  
		var str = "星期"+ a[week];
		return str
	}
	
	static showLoad() {
		uni.showLoading({
			
		})
	}
	
	static hideLoad() {
		uni.hideLoading()
	}
	
	static showTips(msg) {
		uni.showToast({
			title:msg,
			icon:"none"
		})
	}
	
	static showTipsFnc(msg,fnc) {
		uni.showToast({
			title:msg,
			icon:"none",
			success() {
				setTimeout(fnc,1000)
			}
		})
	}
	
	static getToken(){
		let token = uni.getStorageSync("user").token
		if (token) {
			return token
		} else {
			this.showTipsFnc("请先登录",function(){
				uni.reLaunch({
					url:"/pages/user/user"
				})
			})
			return ""
		}
	}
	
	static 	getDate(format='Y') {
		const date = new Date();
		let year = date.getFullYear();
		let month = date.getMonth() + 1;
		let day = date.getDate();
		let hours = date.getHours();
		let min = date.getMinutes()
		let se = date.getSeconds()
		
		month = month > 9 ? month : '0' + month;
		day = day > 9 ? day : '0' + day;
		hours = hours > 9 ? hours : '0' + hours;
		min = min > 9 ? min : '0' + min;
		se = se > 9 ? se : '0' + se;
		
		if (format == "Y") {
			return `${year}`;
		}
		
		if (format == "Y-m")
		{
			return `${year}-${month}`
		}

		if (format == "Y-m-d")
		{
			return `${year}-${month}-${day}`
		}

		if (format == "Y-m-d H:i:s")
		{
			return `${year}-${month}-${day} ${hours}:${min}:${se}`
		}
		if (format == "Y-m-d H:i")
		{
			return `${year}-${month}-${day} ${hours}:${min}`
		}
	}
}

export default Helper